package com.cn.servlet.member;

import com.cn.Dao.AdminDao;
import com.cn.Dao.UserDao;
import com.cn.entity.AdminInfo;
import com.cn.entity.UserInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "UserUPDServlet")
public class UserUPDServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String message="";
        try {
            UserDao userDao=new UserDao();
            UserInfo userInfo= (UserInfo) request.getSession().getAttribute("userInfo");
            String password = request.getParameter("password");
            String name=request.getParameter("name");
            String departmentid=request.getParameter("departmentid");
            String phone=request.getParameter("phone");
            userInfo.setDepartmentid(Integer.valueOf(departmentid));
            userInfo.setName(name);
            userInfo.setPassword(password);
            userInfo.setPhone(phone);
            userDao.Update(userInfo);
        }catch (SQLException throwables) {
            throwables.printStackTrace();
            message="修改失败";
            request.setAttribute("message", message);
            request.getRequestDispatcher("user.jsp").forward(request, response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
